home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / debugger / ddd-1.000 / ddd-1 / ddd-1.4b / ddd / rcssync.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  2.6 KB  |  105 lines

  1. // $Id: rcssync.C,v 1.2 1995/05/02 09:29:22 zeller Exp $ -*- C++ -*-
  2. // List recently changed RCS files
  3.  
  4. // Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
  5. // Written by Andreas Zeller (zeller@ips.cs.tu-bs.de).
  6. // 
  7. // This file is part of the ICE Library.
  8. // 
  9. // The ICE Library is free software; you can redistribute it and/or
  10. // modify it under the terms of the GNU Library General Public
  11. // License as published by the Free Software Foundation; either
  12. // version 2 of the License, or (at your option) any later version.
  13. // 
  14. // The ICE Library is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. // See the GNU Library General Public License for more details.
  18. // 
  19. // You should have received a copy of the GNU Library General Public
  20. // License along with the ICE Library -- see the file COPYING.LIB.
  21. // If not, write to the Free Software Foundation, Inc.,
  22. // 675 Mass Ave, Cambridge, MA 02139, USA.
  23. // 
  24. // ICE is the incremental configuration engine.
  25. // Contact ice@ips.cs.tu-bs.de for details.
  26.  
  27. char rcssync_rcsid[] =
  28.     "$Id: rcssync.C,v 1.2 1995/05/02 09:29:22 zeller Exp $";
  29.  
  30. #include <sys/types.h>
  31. #include <sys/stat.h>
  32. #include <stdlib.h>
  33. #include <errno.h>
  34. #include <stdio.h>
  35. #include <string.h>
  36.  
  37. // For all files in args, check if the corresponding RCS file is newer.
  38. // If so, print the name of the RCS file on standard output.
  39. // Thus, you may use co `rcssync *.C` to check out all recent .C files.
  40. int main(int argc, char *argv[])
  41. {
  42.     int errors = 0;
  43.  
  44.     for (int i = 1; i < argc; i++)
  45.     {
  46.     int checkout = 0;
  47.  
  48.     char file[BUFSIZ];
  49.     char rcsfile[BUFSIZ];
  50.     strcpy(file, argv[i]);
  51.     strcpy(rcsfile, argv[i]);
  52.  
  53.     int j = strlen(rcsfile);
  54.     while (j >= 0 && rcsfile[j] == '/')
  55.         j--;
  56.     while (j >= 0 && rcsfile[j] != '/')
  57.         j--;
  58.     if (j < 0)
  59.     {
  60.         char buf[BUFSIZ];
  61.         strcpy(buf, "RCS/");
  62.         strcat(buf, rcsfile);
  63.         strcpy(rcsfile, buf);
  64.     }
  65.     else
  66.     {
  67.         char buf[BUFSIZ];
  68.         strncpy(buf, rcsfile, j + 1);
  69.         buf[j + 1] = '\0';
  70.         strcat(buf, "RCS");
  71.         strcat(buf, rcsfile + j);
  72.         strcpy(rcsfile, buf);
  73.     }
  74.     strcat(rcsfile, ",v");
  75.  
  76.     // printf("Checking: %s vs. %s\n", file, rcsfile);
  77.  
  78.     struct stat filestat;
  79.     int ret = stat(file, &filestat);
  80.     if (ret != 0)
  81.     {
  82.         perror(file);
  83.         checkout = 1;
  84.     }
  85.     else
  86.     {
  87.         struct stat rcsstat;
  88.         ret = stat(rcsfile, &rcsstat);
  89.         if (ret != 0)
  90.         {
  91.         perror(rcsfile);
  92.         errors++;
  93.         continue;
  94.         }
  95.  
  96.         checkout = rcsstat.st_mtime > filestat.st_mtime;
  97.     }
  98.  
  99.     if (checkout)
  100.         printf("%s\n", rcsfile);
  101.     }
  102.  
  103.     return errors > 0;
  104. }
  105.